#ifndef _PHOENIX_INITIALIZER_HPP
#define _PHOENIX_INITIALIZER_HPP

#if (!defined NDEBUG)
	#define PHX_DEBUG 1
#endif

#ifdef PHX_DEBUG
#	define debugstring printf
#else
#	define debugstring(format, ...)
#endif

#ifdef PHX_DEBUG
#define DEBUG_SECTION(code) code
#else
#define DEBUG_SECTION(code)
#endif

#ifdef WIN32
#	include <Windows.h>
#	define PHX_WINDOWS
#endif

#include <GL/glew.h>
#include <GLFW/glfw3.h>

#ifdef PHX_WINDOWS
	#define GLFW_EXPOSE_NATIVE_WIN32 1
	#define GLFW_EXPOSE_NATIVE_WGL 1
	#include <GLFW/glfw3native.h>
#endif

#include <cstdio>
#include <direct.h>
#include <string>
#ifdef PHX_WINDOWS
#	define GetCurrentDir _getcwd
#else
#	include <unistd.h>
#	define GetCurrentDir getcwd
#endif

namespace phx
{

static std::string getCurrentDir()
{
	char cCurrentPath[FILENAME_MAX];
	if(GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
		return std::string(cCurrentPath);
	return std::string("NO PATH FOUND!");
}

}

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#define phxInt GLint
#define phxUint GLuint
#define phxFloat GLfloat

static bool printGLerror()
{
	GLenum glError = glGetError();
	if(glError != GL_NO_ERROR)
	{
		printf("OpenGL Error[%d]: %s\n", glError, glewGetErrorString(glError));
		return false;
	}
	return true;
}

namespace phx
{

// Call this function to initialize game loop and leave updating calls to the system.
// bool CloseWhenWindowsClose:
//		true: close the program when all windows are closed, or when phx::leaveMainLoop() is called
//		false: program will continue running even after all windows has been closed,
//			and phx::leaveMainLoop() has to be called when you want to close the program
void mainLoop(bool closeWhenWindowsClose = true);

// Leave main loop and close the program
void leaveMainLoop();

}

#endif